home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / gcoope10.zip / GENERICS.TXT < prev    next >
Text File  |  1994-07-22  |  5KB  |  163 lines

  1.  
  2.     The generic functions in GCOOPE Version 1.0 initial release.
  3.  
  4.             by Brian Lee Price
  5.  
  6.         Released as Public Domain  July, 1994.
  7.  
  8.  
  9.  
  10. I.  The flavors of New,  the following constructors are defined:
  11.  
  12.     A.  Class constructor
  13.  
  14.     form of call;
  15.  
  16.         1. normal
  17.  
  18.         newclass=g(New)(Class, classVarSize, instanceVarSize,
  19.             ancestor list terminated by END);
  20.  
  21.  
  22.         2. strong typing
  23.  
  24.         newclass=NEW(Class)(Class, classVarSize, instanceVarSize,
  25.             ancestor list terminated by END);
  26.  
  27.     this call creates an instance of Class, ie a new class.
  28.     should only be called from within a CLASS_INSTALL function.
  29.  
  30.  
  31.  
  32.     B.  Other constructors
  33.  
  34.     form of call;
  35.  
  36.         1. normal
  37.  
  38.         newobject=g(New)(className, initialParameters);
  39.  
  40.         2. strong typing
  41.  
  42.         newobject=NEW(className)(className, initialParameters);
  43.  
  44.     The form of the parameter list is given in each class description.
  45.  
  46.  
  47. II. Other generic functions:
  48.  
  49.     A. Impossible to prototype generics;
  50.  
  51.     changeVal and valueOf are pretty much impossible to deal with
  52.     under strong typing.  For valueOf, you can use the return
  53.     value type casts given in gcoope10.h.
  54.  
  55.     The trouble with changeVal is although it always returns an
  56.     object type and always takes an object type as the first
  57.     parameter, the second parameter is a different type for every
  58.     object class it is defined for.  Still, I'd rather pass by
  59.     value and take my chances with weak typing than go through
  60.     the pains of passing by pointer.
  61.  
  62.     valueOf has the opposite problem, it always takes only one
  63.     parameter of type object, but its return value changes for
  64.     each object class it is defined for.  In gcoope10.h there
  65.     are some return value method typecasts defined that can
  66.     help you avoid many problems, but you still must know what
  67.     type to expect.
  68.  
  69.     For both of the above, the primary usage should be by other
  70.     class definitions rather than applications programs, this
  71.     should at least localize any problems.
  72.  
  73.     Accessing:
  74.  
  75.        The above generics should be called in the following
  76.        manner:
  77.  
  78.        1. normal
  79.  
  80.         returnValue= ((returnTypeCast)g)(genName)(parms);
  81.  
  82.        2. strong typing
  83.  
  84.         returnValue= ((returnTypeCast)g)(GEN(genName))(parms);
  85.  
  86.  
  87.     B. Standard format generics;
  88.  
  89.     The following generic functions have a standardized interface,
  90.     they always return the same type and always take the same
  91.     number and type of parameters regardless of the class definition
  92.     for which they are defined.
  93.  
  94.     I'm going to show them here as standard function prototypes, but
  95.     bear in mind that you must call them as follows:
  96.  
  97.        1. normal
  98.  
  99.         returnValue= ((returnTypeCast) g)(genName)(parameters);
  100.  
  101.        2. strong typing
  102.  
  103.         returnValue= G(genName)(parameters);
  104.  
  105.  
  106.     Here are the generics given as standard prototypes:
  107.  
  108.  
  109.         object     reSize(object, word)
  110.         object     putElem(object, word, void *)
  111.         void *     getElem(object, word)
  112.         word    sizeOf(object)
  113.         word    lengthOf(object)
  114.         word    numElems(object)
  115.         object    classOf(object)
  116.         object    ivSize(object)
  117.         object  respondsTo(object, generic)
  118.         object  deepCopy(object)
  119.         object  shallowCopy(object, object)
  120.         object    asString(object)
  121.         object    asHexStr(object)
  122.         object  asShortInt(object)
  123.         object  asLongInt(object)
  124.         object    asUnsigned(object)
  125.         object  asChar(object)
  126.         int      addUnit(object, void *)
  127.         object  rmvUnit(object, int)
  128.         void *  getUnit(object, int)
  129.         object  compact(object, boolean)
  130.         long    getPos(object)
  131.         object  strmErr(object)
  132.         object  setPos(object, long, int)
  133.         object  putByte(object, byte)
  134.         object  getByte(object)
  135.         object    clrErr(object)
  136.         object  SetBuf(object, char *, int, word)
  137.         object  Flush(object)
  138.         object  Stat(object)
  139.         int    Putc(object, char)
  140.         int      Getc(object)
  141.         int    UnGet(object, char)
  142.         int    Puts(object, const char *)
  143.         void *  Gets(object, char *, int)
  144.         int    Write(object, const char *, word, word)
  145.         int    Read(object, char *, word, word)
  146.         void *  addressOf(object)
  147.  
  148.         Most of these generics should be self explanatory, however
  149.     consult the class definitions for details.  Also note that when
  150.     possible, I have attempted to stay with the standard ANSI C
  151.     function library prototypes.
  152.  
  153.         A final reminder, don't try to use the prototypes above
  154.     directly, use either the return type casting as needed or
  155.     the strong typing option with the g or G dispatch call.
  156.  
  157.         The above goes to show that if you beat C firmly about the
  158.     neck and shoulders with an appropriately sized sledgehammer, you
  159.     can combine a reasonable degree of static type checking with
  160.     run-time OOP flexibility.
  161.  
  162.  
  163.